#!/bin/bash
## test home
testdir=$(cd $(dirname $0)/; pwd)
## word home
workdir=$(dirname $testdir)
cd $workdir

module=query
app=falcon-$module
pidfile=var/app.pid
logfile=var/app.log
control=./control
httpprex="127.0.0.1:9966"

## statistics
function counter(){
    curl -s "$httpprex/counter/all" | python -m json.tool
}

function conn_pool(){
    curl -s "$httpprex/proc/connpool"
}


## tail
function tail_log(){
    $control tail
}

## build
function build(){
    $control build
    [ $? -eq 0 ] && echo -e "build ok" || { echo -e "build error"; exit 1; }
}
function start(){
    $control start
}
function stop(){
    $control stop
}


action=$1
case $action in
    "build")
        build
        ;;
    "start")
        start
        ;;
    "stop")
        stop
        ;;
    "restart")
        stop && build && sleep 1 && start
        ;;
    "tail")
        tail_log
        ;;
    "connpool")
        conn_pool
        ;;
    *)
        counter 
        ;;
esac

